package com.hand.wyc24548.api.controller.v1;

import com.hand.wyc24548.config.SwaggerApiConfig;
import com.hand.wyc24548.domain.entity.Company;
import com.hand.wyc24548.domain.repository.CompanyRepository;
import io.choerodon.core.domain.Page;
import io.choerodon.core.iam.ResourceLevel;
import io.choerodon.mybatis.pagehelper.domain.PageRequest;
import io.choerodon.swagger.annotation.Permission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.hzero.core.base.BaseController;
import org.hzero.core.util.Results;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author wangyc
 * @create 2019/8/5 19:41
 */

@Api(tags = SwaggerApiConfig.COMPANY)
@RestController("company.v1")
@RequestMapping("/v1/company")
public class CompanyController extends BaseController {

    private final CompanyRepository companyRepository;

    public CompanyController(CompanyRepository companyRepository) {
        this.companyRepository = companyRepository;
    }

    @Permission(level = ResourceLevel.ORGANIZATION)
    @ApiOperation(value = "分页查询公司信息")
    @GetMapping("/companyId")
    public ResponseEntity<Page<Company>> selectCompany(/*@PathVariable Long companyId,*/Company company,PageRequest pageRequest){
        return Results.success(companyRepository.selectCompany(company,pageRequest));
    }


    @Permission(level = ResourceLevel.SITE)
    @ApiOperation(value = "根据companyNumber查询公司信息")
    @GetMapping("/{companyNumber}")
    public ResponseEntity<Company> selectDetail(@PathVariable String companyNumber){
        return Results.success(companyRepository.selectDetailByCompanyNumber(companyNumber));
    }


}
